package app.fugema.shop.main.wallet.model;

import android.text.TextUtils;

import androidx.databinding.Bindable;

import com.base.common.view.adapter.bean.ChildBaseBean;
import app.fugema.shop.BR;
import app.fugema.shop.R;
import app.fugema.shop.main.order.model.PaymentTpye;

import java.util.ArrayList;
import java.util.List;

public class PayBen extends ChildBaseBean
{

    //0?3  钱包    1，支付宝  2，微信   （不是数字）

    // WeiXinPay_App  Alipay_App
    private String payType;
    private String name;
    //private String desc;
    private int icon;

    private PaymentTpye  paymentTpye;

    public PayBen()
    {
    }

    public PayBen(PaymentTpye paymentTpye)
    {
        setPaymentTpye(paymentTpye);
    }

    public int getIcon()
    {
        switch (payType)
        {
            case "0":
                icon = R.mipmap.ic_pay_wallet;
                break;
            case "Alipay_App":
                icon = R.mipmap.ic_pay_alipay;
                break;
            case "WeiXinPay_App":
                icon = R.mipmap.ic_pay_wxpay;
                break;
        }
        return icon;
    }

    @Bindable
    public int getCheckedRes()
    {
        if (getSelected())
        {
            return R.mipmap.ic_radio_checked;
        } else {
            return R.mipmap.ic_radio_unchecked;
        }
    }

    public void setCheckedRes()
    {
        notifyPropertyChanged(BR.checkedRes);
    }


    @Override
    public void setSelected(boolean selected)
    {
        super.setSelected(selected);
        setCheckedRes();
    }

    public String getPayType()
    {
        return payType;
    }

    public void setPayType(String payType)
    {
        this.payType = payType;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public void setIcon(int icon)
    {
        this.icon = icon;
    }

    public PaymentTpye getPaymentTpye()
    {
        return paymentTpye;
    }

    public void setPaymentTpye(PaymentTpye paymentTpye)
    {
        setName( paymentTpye.getName() );
        if(!TextUtils.isEmpty( paymentTpye.getId() ))
        {
          String payType = paymentTpye.getId().substring(paymentTpye.getId().lastIndexOf(".")+1,paymentTpye.getId().length());
          setPayType( payType );
        }
        this.paymentTpye = paymentTpye;
    }

    /**
     *   获取 支持的 支付方式
     * @param paymentTpyeList
     * @return
     */
    public static List<PayBen> getPayListByPaymentType(List<PaymentTpye>  paymentTpyeList )
    {
        List<PayBen> list = new ArrayList<>();
        for (PaymentTpye paymentTpye : paymentTpyeList)
        {
            PayBen pay = new PayBen(paymentTpye);
            list.add( pay );
        }
        return list;
    }

}
